/*
 * table_TypeCmpStack_t.c
 *
 *  Created on: 2012-5-14
 *      Author: guanxiaoying
 */

#include "../../parser/coredef.h"
typedef struct _TYPECMPSTACK{
	AST astType1;
	AST astType2;
}TYPECMPSTACK, *PTYPECMPSTACK;

#define TableSize  (sizeof(TYPECMPSTACK))
#define TableType  PTYPECMPSTACK
#define stTable stTypeCmpStkManager.memoryBlocks
#define maxTable stTypeCmpStkManager.maxRecordNum
#define  maxNumPerBlk  (stTypeCmpStkManager.astMaxNum_Block)


/* get the object */
static TABLEMANAGER stTypeCmpStkManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stTypeCmpStkManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stTypeCmpStkManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stTypeCmpStkManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stTypeCmpStkManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stTypeCmpStkManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}

static AST getType1( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType1;
}
static AST setType1( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType1 = value;
}
static AST getType2( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType2;
}
static AST setType2( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType2 = value;
}

const TYPECMPSTACKACCESS stTypeCmpStkAccess = {
		//		BOOL (*clear)( VOID );
				ClearTable,
		//		BOOL (*reset)( VOID );
				ResetTable,
		//		BOOL (*alloc)( AST );
				AllocTable,
		//		AST  (*getMax)( VOID );
				getMaxLineNum,
				{
						getType1,
						setType1
				},
				{
						getType2,
						setType2
				}
};
